package com.sisgh.jefdv1.cmd.command.has.one.impl;

import com.sisgh.jefdv1.cmd.command.has.arg.Arguments;
import com.sisgh.jefdv1.cmd.command.has.one.OneArgCommand;
import com.sisgh.jefdv1.core.exec.Executor;
import com.sisgh.jefdv1.exception.cmd.exec.ExecuteCommandException;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class ShowCommand extends OneArgCommand {
    private static final String LONG_NAME = "database";
    private static final String SHORT_NAME = "db";
    private static final boolean REQUIRED = true;

    private static final String CMD = "show";

    @Override
    protected String getCmd() {
        return CMD;
    }

    public ShowCommand() {
        super(Arguments.option(LONG_NAME, SHORT_NAME, REQUIRED));
    }

    @Override
    public Executor execute(Executor executor) throws ExecuteCommandException {
        // todo
        System.out.println(CMD + " " + arg.values().get(0) + " 执行中");

        List<String> dbs = new ArrayList<>();

        try {
            dbs = executor.showDBs();
        } catch (SQLException e) {
            throw new ExecuteCommandException(e.getMessage(), e);
        }

        

        return executor;
    }
}
